Skip to content

emu: 客体时钟源一直用 TSC(tsc=nowatchdog) - #187

Merged
qiyinxi merged 1 commit into
ModAVD:mainfrom
qiyinxi:fix/tsc-nowatchdog
Nov 17, 2026
Merged

qiyinxi merged 1 commit into
ModAVD:mainfrom
qiyinxi:fix/tsc-nowatchdog

Conversation

@qiyinxi

@qiyinxi qiyinxi commented Nov 17, 2026

Copy link
Copy Markdown
Member

Refs ModAVD/ModAVD#110

问题

一台连续开了约 14 小时的实例(明日方舟 + MAA)突然变得很卡:游戏从 55–60 fps 掉到约 5 fps,而且一直卡到下次冷启动。

现场采样:

  • 游戏渲染线程 UnityGfxDeviceWorker 占满一个核,其中约 90% 是内核态;simpleperf 里 read_hpet 占 72%,goldfish_address_space 的 as_ioctl 占 14%。
  • 宿主显卡(qemu 的 3D 约 4%)和宿主的渲染线程都很闲;客体内存没有回收压力。
  • 客体时钟源已经从 tsc 换成了 hpet。内核日志:
clocksource: timekeeping watchdog on CPU4: hpet read-back delay of 209700ns, attempt 3, marking unstable
tsc: Marking TSC unstable due to clocksource watchdog
clocksource: Switched to clocksource hpet

这正好是 #110 列出的第三种原因:运行中看门狗读 hpet 太慢。WHPX 不给客体 kvm-clock,tsc 一停用就只剩 QEMU 模拟的 hpet,之后每次读时钟都要退出到宿主。看门狗用 hpet 校验 tsc,主机一忙,读一次 hpet 就可能超过门限,连续三次超时就会停用 tsc。那次开机的 14 小时里,客体记了 78 次 hpet 读得慢,第 13.8 小时连续三次没过。所以开得越久,越早会碰上。

客体 CPU 报了 constant_tsc 和 nonstop_tsc,但没有 tsc_adjust。6.1 内核要三个都有才会自动让 TSC 免检,所以看门狗一直在检查 TSC。

改动

Windows 上给客体内核加 tsc=nowatchdog(通过 -qemu -append,模拟器会把它合并进内核命令行,不会替换原有参数)。

  • 它只是让看门狗不再检查 TSC;开机时的各核 TSC 同步检查照做,真的不同步还是会被发现。
  • 没用 tsc=reliable:那个连同步检查也一起跳过。以前在没修 TSC 的模拟器上用过它,system_server 读到时间倒退后崩溃了。
  • macOS(ARM64)和 Linux(KVM,有 kvm-clock)不加。

测试

  • go test ./internal/emu/... 通过;TestBuildLaunchArgs 两张参考表都加上了 -append tsc=nowatchdog。
  • 变异检查:把这行去掉以后 TestBuildLaunchArgs 失败,恢复后通过。
  • 实机(Windows 11 + WHPX,0.41.1 的模拟器,测试根):用这个分支的命令行开机,/proc/cmdline 里有 tsc=nowatchdog,原有参数都还在,时钟源是 tsc;开明日方舟跑到主界面,没有新的崩溃(只有一直都有的 com.google.android.bluetooth SIGABRT),关机正常。
  • 长时间运行和多游戏放到发版回归一起测。

After hours of running, the guest clocksource watchdog can give up on the
TSC when HPET reads are slow three times in a row, leaving the emulated
HPET as the only clock; every clock read then exits to the host and games
drop to a few fps until the next cold boot. Pass tsc=nowatchdog on Windows
so the watchdog no longer checks the TSC; the boot-time TSC sync check
still runs.

Refs ModAVD/ModAVD#110
@qiyinxi qiyinxi added the bug Something isn't working label Nov 17, 2026
@qiyinxi
qiyinxi added this pull request to the merge queue Nov 17, 2026
Merged via the queue into ModAVD:main with commit 51e989d Nov 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant